﻿@page "/pages/authentication/Login-v2"
@layout EmptyLayout
@inherits BaseComponentBase
@inject WebsiteAuthenticator WebsiteAuthenticator
<MRow Class="max-height ma-0">
    <MCol Md=4 Sm=12 Class="neutral-lighten-5">
        <div class="d-flex pb-12" style="height: calc(100% - 88px);">
            <div style="width:450px;" class="ma-auto">
                <h3 class="neutral-lighten-1--text">让操作更简单</h3>
                <div class="mt-12 neutral-lighten-1--text">
                    让变化更简单，让视觉更美好，让体验更丰富。
                </div>
                <image class="mt-12" src="/img/login/left.svg"></image>
            </div>
        </div>
    </MCol>
    <MCol Md=8 Sm=12 Class="fill-lighten-1 block-center">
        <MCard Width=510 Height=680 Class="mx-auto my-auto">
            <div style="height:60px;"></div>
            <div class="mt-2 mx-auto text-center" style="width:420px;">
                <MAvatar Size=80>
                    <MImage Src="/img/avatar/1.svg">
                    </MImage>
                </MAvatar>
                <h5 class="mt-2 mb-12">汽车衡无人值守系统 </h5>

                <MTextField TValue="string" Label="账户" Placeholder="请输入账号" @bind-Value=@LoginName Outlined HideDetails="@("auto")">
                </MTextField>
                <MTextField TValue="string" Class="mt-10" Label="密码" Type="@(_show ? "text" : "password")"
                            Placeholder="请输入密码" @bind-Value=@PassWord AppendIcon="@(_show ? "mdi-eye" : "mdi-eye-off")"
                            OnAppendClick="()=>_show = !_show" Outlined HideDetails="@("auto")">
                </MTextField>

                <MButton Class="mt-11 rounded-4 text-btn white--text" OnClick=OnLogin Height=46 Width=340 Color="primary">
                    登陆
                </MButton>
            </div>
        </MCard>
    </MCol>
</MRow>

<MOverlay Value="overlay">
		<MProgressCircular indeterminate
						   Size="20"></MProgressCircular>
    登录成功！正在初始化数据！
	</MOverlay>
<a href="https://beian.miit.gov.cn/" target="_blank" class="neutral-lighten-3--text"
    style="position:absolute;bottom:48px;margin-left:63%;text-decoration:none;font-size:14px;"></a>


            @code {
    [Inject]
    public AjaxService AjaxService { get; set; }
    [Inject]
    public NavigationManager Navigation { get; set; } = default!;
    private LoginInputDTO loginMode=new();
    private bool _show;
    private string LoginName { get; set; }
    private string PassWord { get; set; }
    private  bool overlay=false;
    public async void OnLogin(MouseEventArgs args)
    {
        overlay = true;
        loginMode.Account = LoginName??"admin2";
        loginMode.Password = PassWord??"123456";
        var lo=await WebsiteAuthenticator.LoginAsync(loginMode);
        if (lo)
        {
            overlay = false;
            Navigation.NavigateTo(Navigation.BaseUri + "home/home");
        }
        else
        {
            overlay = false;
            await PopupService.ToastAsync("登录失败，请检查用户名或密码是否正确", AlertTypes.Error);
        }
    }
}
